<template>
	<view style="padding: 30rpx;">
		<template v-if="arctileObj">
			<view class="article-con">
				<view class="title">{{arctileObj.title}}</view>
				<view class="uni-flex list-info" style="margin-bottom: 15px;">
					<view class="date" v-if="arctileObj.publishTime">
						<uni-icons type="calendar" size="12" color="#9498A0"></uni-icons>
						<text>{{arctileObj.publishTime}}</text>
					</view>
					<view class="see">
						<uni-icons type="eye" color="#9498A0" size="14"></uni-icons>
						<text>{{arctileObj.browseNum}}</text>
						<uni-fav style="float: right; margin-left: 30rpx;" :checked="isFav" @click="setFav(isFav)"
							:circle="true" bg-color="#B4B5B7" bg-color-checked="rgba(255, 90, 90, 0.08)"
							fg-color="#ffffff" fg-color-checked="#FF5A5A" />
					</view>
				</view>
			</view>
			<view class="arcticle"><rich-text :nodes="nodes"></rich-text></view>
		</template>
		<view class="uni-loadmore" v-if="showLoadMore">加载中...</view>
		<!-- <view class="article-con">
					<view class="title">残疾优抚对象抚恤金</view>
					<view class="uni-flex list-info">
						<view class="date">
							<uni-icons type="calendar" size="12" color="#9498A0"></uni-icons>
							<text>2023-04-21  09:00</text>
						</view>
						<view class="see">
							<uni-icons type="eye" color="#9498A0" size="14"></uni-icons>
							<text>894</text>
							<uni-fav style="float: right; margin-left: 30rpx;" :checked="false" :circle="true" bg-color="#B4B5B7"
								bg-color-checked="rgba(255, 90, 90, 0.08)" fg-color="#ffffff" fg-color-checked="#FF5A5A" />			
						</view>
					</view>
				</view>
				<view class="arcticle">
					<view class="title">补贴对象：</view>
					<text>一级因战、因公、因病残疾军人抚恤金标准为每人每年80140元、77610 元、75060元，分别比2017年提高了7290元、7060元、6820元。
		烈属、因公牺牲军人遗属、病故军人遗属定期抚恤金标准分别提高到每人每年25440元、 21850元和20550元。在乡退伍红军老战士、在乡西路军红军老战士和红军失散人员生活补助标准，分别提高到每人每年55570元、55570元和25070元。
		这是自改革开放以来，国家第25次提高残疾军人残疾抚恤金标准，第28次提高“三属”定期抚恤金标准和“三红”生活补助标准。</text>
					<image src="https://staticfile-yj.obs.myhuaweicloud.com/arcimg/%E9%85%8D%E5%9B%BE9.png" mode="widthFix"></image>
				</view> -->
	</view>
</template>

<script>
	import {
		appDetailAllowancePolicy,
		deleteCollection,
		addCollection
	} from "@/api/user.js";
	export default {
		data() {
			return {
				isFav: false,
				parmas: '',
				arctileObj: null,
				showLoadMore: false,
				nodes: [],
				strings: '',
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option.id); //打印出上个页面传递的参数。
			this.parmas = option.id;
			this.showLoadMore = true;
			console.log("onload", this.arctileObj)
			this.appDetailAllowancePolicy(this.parmas);
		},
		onPullDownRefresh() {
			this.showLoadMore = true;
			this.appDetailAllowancePolicy(this.parmas);
		},
		methods: {
			async appDetailAllowancePolicy(options) {
				const res = await appDetailAllowancePolicy(options);
				console.log(res)
				this.arctileObj = res.returnObj;
				if(this.arctileObj.myFavorite > 0){
					this.isFav = true
				}else{
					this.isFav = false
				}
				this.nodes = this.arctileObj.content;
				console.log("nodes", this.arctileObj.content)
				this.showLoadMore = false;
			},
			async addCollection(options){
				const res = await addCollection(options);
				if(res.success){
					uni.showToast({
						title:'收藏成功！'
					})
					this.isFav = true;
				}
			},
			
			async deleteCollection(options){
				const res = await deleteCollection(options);
				if(res.success){
					uni.showToast({
						title:'已取消收藏！'
					})
					this.isFav = false
				}
			},
			setFav() {
				let options = {
					serviceType:'7',
					serviceId:this.arctileObj.id
				}
				if(this.isFav){
					this.deleteCollection([options])
				}else{
					this.addCollection(options)
				}
				this.$forceUpdate()
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-image: url("https://staticfile-yj.obs.cn-north-4.myhuaweicloud.com/course-bg.png");
		background-repeat: no-repeat;
		background-size: 100% auto;
		background-color: #fff;
	}

	.article-con .title {
		color: #283241;
		font-size: 40rpx;
		font-weight: 500;
		line-height: 28px;
		margin-bottom: 15px;
	}

	.article {
		padding: 30rpx;
	}

	.arcticle .title {
		font-size: 32rpx;
		line-height: 24px;
		font-weight: 500;
		color: #283241;
	}

	.arcticle text {
		font-size: 28rpx;
		color: #646A74;
		line-height: 26px;
	}

	.arcticle image {
		width: 100%;
		margin: 20px auto;
	}
</style>